using System;
using System.CodeDom.Compiler;
using System.Diagnostics;
using System.Windows;
using System.Windows.Markup;
using Common;

namespace PCR.PCRControls
{
	public partial class HighProgram : Window, IComponentConnector
	{
		private Step _step;

		public HighProgram(Step step)
		{
			InitializeComponent();
			_step = step;
			cProgram.IsChecked = _step.Program;
			cWhileNum.Value = _step.WhileNum;
			cAddSecond.SelectedIndex = _step.AddSecond;
			cTimeSecond.Value = _step.TimeSecond;
			cAddTempt.SelectedIndex = _step.AddTempt;
			cTemptChange.Value = _step.TemptChange;
			cProgram1.IsChecked = _step.Program1;
			cTemptRate.Value = _step.TemptRate;
		}

		private void Button_Click(object sender, RoutedEventArgs e)
		{
			if (cProgram.IsChecked.Value)
			{
				if (cWhileNum.Value > (double)_step.SParent.WhileNum || cWhileNum.Value < 0.0)
				{
					MessageBox.Show(string.Format(Utility.GetMessage("msg_cycle_out_of_range"), 1, _step.SParent.WhileNum), Utility.GetMessage("Warning"));
					cWhileNum.Value = 1.0;
					cWhileNum.Focus();
					return;
				}
				int num = TimeMax(_step.StayMinute, _step.StaySecond, _step.SParent.WhileNum, _step.WhileNum, cAddSecond.SelectedIndex);
				if (cTimeSecond.Value > (double)num || cTimeSecond.Value < 0.0)
				{
					MessageBox.Show(Utility.GetMessage("msg_time_out_of_range"), Utility.GetMessage("Warning"));
					cTimeSecond.Focus();
					return;
				}
				double num2 = RateMax(_step.Temperature, _step.WhileNum, _step.SParent.WhileNum, cAddTempt.SelectedIndex);
				if (cTemptChange.Value > num2 || cTemptChange.Value < 0.0)
				{
					MessageBox.Show(Utility.GetMessage("msg_temperature_out_of_range"), Utility.GetMessage("Warning"));
					cTemptChange.Focus();
					return;
				}
			}
			if (cProgram1.IsChecked.Value && (cTemptRate.Value > 4.0 || cTemptRate.Value < 0.1))
			{
				MessageBox.Show(Utility.GetMessage("msg_temperature_ratio_out_of_range"), Utility.GetMessage("Warning"));
				cTemptRate.Focus();
				return;
			}
			_step.Program = cProgram.IsChecked.Value;
			_step.WhileNum = Convert.ToInt32(cWhileNum.Value);
			_step.AddSecond = cAddSecond.SelectedIndex;
			_step.TimeSecond = Convert.ToInt32(cTimeSecond.Value);
			_step.AddTempt = cAddTempt.SelectedIndex;
			_step.TemptChange = cTemptChange.Value;
			_step.Program1 = cProgram1.IsChecked.Value;
			_step.TemptRate = cTemptRate.Value;
			base.DialogResult = true;
			Close();
		}

		public int TimeMax(int StayMinute, int StaySecond, int WhileNum, int StartWhile, int AddSecond)
		{
			int num = 0;
			if (AddSecond == 0)
			{
				return (5999 - (StayMinute * 60 + StaySecond)) / (WhileNum - StartWhile + 1);
			}
			return (StayMinute * 60 + StaySecond) / (WhileNum - StartWhile + 1);
		}

		public double RateMax(double Temperature, int StartWhile, int WhileNum, int AddTempt)
		{
			double num = 0.0;
			if (AddTempt == 0)
			{
				return (99.0 - Temperature) / (double)(WhileNum - StartWhile + 1);
			}
			return (Temperature - 4.0) / (double)(WhileNum - StartWhile + 1);
		}

		private void Cancel_Click(object sender, RoutedEventArgs e)
		{
			Close();
		}

		[DebuggerNonUserCode]
		[GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
		internal Delegate _CreateDelegate(Type delegateType, string handler)
		{
			return Delegate.CreateDelegate(delegateType, this, handler);
		}
	}
}
